package com.zyzd.baseretrofit.net;


import com.zyzd.baseretrofit.bean.remote.ApiResultBean;
import com.zyzd.baseretrofit.exception.ApiException;
import com.zyzd.baseretrofit.utils.api.ErrorCodeUtil;
import com.zyzd.commontools.log.TLog;

import rx.functions.Func1;


/**
 * Created by 李宗源 on 2017/4/25.
 */

public class HttpResultFunc<T> implements Func1<ApiResultBean<T>, T> {
    @Override
    public T call(ApiResultBean<T> resultBean) {
        if (resultBean == null) {
            TLog.d("zyzd", "HttpResultFunc>>call 请求数据为空");
            throw new ApiException("请求数据为空", ErrorCodeUtil.ERROR_DATA_NULL);
        }

        if (resultBean.getErrorNo() != 101000) {
            throw new ApiException(resultBean.getMessage(), resultBean.getErrorNo());
        }
        return resultBean.getData();
    }
}
